PreviousNextTracker indexSee it online !

(160/182) 353 - Beauty: clang-format plugin for C++

clang-format is a command-line formatting program for C++ that works much better than any other formatting tools.

Submitted ezust - 2015-10-13 23:58:05.800000 Assigned daleanson
Priority 5 Labels
Status open Group
Resolution None

Comments

2015-10-13 23:58:59.969000
ezust

Ticket moved from /p/jedit/feature-requests/502/

2015-10-14 21:44:17.116000
daleanson

I did a little googling since I'm in the middle of some Beauty plugin updates anyway, so I thought I might take this on. It looks like clang-format is written in python, which I don't know, and formats C++, which I haven't used in about 15 years, so someone else should make a separate plugin for this. It should be straightforward for someone with python, C++, and java experience to package up a plugin to work with the Beauty plugin. Here are the details from the Beauty plugin docs:

Adding a new beautifier/formatter is quite simple:

Write a formatter that implements beauty.beautifiers.Beautifier. You'll need to implement only the String beautify(String text) method. Your formatter will be passed the complete contents of a buffer in the text parameter, and should return formatted text. The buffer contents will be replaced with this returned text. Create a simple plugin that contains this formatter.

Add a services.xml file to your plugin like this:
<?xml version="1.0"?>
<!DOCTYPE SERVICES SYSTEM "services.dtd">

<SERVICES>
<SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="lispy">
new lisp.lispy.Beautify();
</SERVICE>
</SERVICES>

For NAME , either use the name of the editing mode that the beautifier supports, or a unique name for your plugin. The beanshell code must return an object that can be cast to beauty.beautifiers.Beautifier .

For each editing mode that your beautifier supports, add a line to your plugin properties file like this:

mode.MODENAME.beauty.beautifier=NAME

where MODENAME is the name of an editing mode that your beautifier supports, and NAME is the same name used in the services.xml file. So continuing the example, you might have:

mode.lisp.beauty.beautifier=lispy

for your beautifier that supports the Lisp language.

Release your plugin.

2015-10-15 06:54:39.097000
kerik-sf

A generic "external formatter" would be useful, piping buffer content to an external program and returning the external program's output. It could be developped as part of the clang-format plugin and not worry with the configuration ui at first.

2015-12-11 20:53:12.712000
daleanson

Alan, I added CLangBeauty in jEdit SVN. It's based on Eric's OuterBeauty and seems to work well. Would you give it a try and if it seems okay, let me know and I'll put in a release request.

2015-12-11 20:53:23.633000
daleanson

- **assigned_to**: Dale Anson
- **Group**: none -->

2015-12-11 22:43:32.937000
ezust

I tried it out and it puts all #include statements on the same line. I am pretty sure that is a setting we can configure so it won't do that. Let me investigate before you release it.

2015-12-11 23:33:48.795000
daleanson

There are a lot of other settings that could be made, I only implemented
the "style" setting. See this page:
http://clang.llvm.org/docs/ClangFormatStyleOptions.html

It would be straightforward to add these to the plugin options.

On Fri, Dec 11, 2015 at 3:43 PM, Alan Ezust <ezust@users.sf.net> wrote:

> I tried it out and it puts all #include statements on the same line. I am
> pretty sure that is a setting we can configure so it won't do that. Let me
> investigate before you release it.
> ------------------------------
>
> * [plugin-feature-requests:#353] Beauty: clang-format plugin for C++ *
>
> *Status:* open
> *Group:*
> *Created:* Tue Oct 13, 2015 11:58 PM UTC by Alan Ezust
> *Last Updated:* Fri Dec 11, 2015 08:53 PM UTC
> *Owner:* Dale Anson
>
> clang-format is a command-line formatting program for C++ that works much
> better than any other formatting tools.
> ------------------------------
>
> Sent from sourceforge.net because you indicated interest in
> https://sourceforge.net/p/jedit/plugin-feature-requests/353/
>
> To unsubscribe from further messages, please visit
> https://sourceforge.net/auth/subscriptions/
>